var mobile="";



$(document).ready(function () {
$.jgrid.defaults.styleUI = "Bootstrap";
$("#table_list_1").jqGrid({
    data: [],
    datatype: "local",
    height: "100%",
    autowidth: true,
    shrinkToFit: true,
    rowNum: 20,
    rowList: [10, 20, 30,60,90,100,200,500],
    colModel: [ {
        name: 'cmmd', index: 'cmmd', align:"center",width: 28, label: "命令码", align: 'center',
        formatter: function (value, options, row) {

            if(value=="19"){

                  
                return "开屏";

            }
            if(value=="18"){

                  
                return "关屏";

            }
          //if(value=="18"){

                  
              //  return "切换app操作";

            //}
            if(value=="46"){

                  
                return "清空节目";

            }
            if(value=="192"){

                  
                return "发送节目";

            }
            if(value=="36"||value=="52"){

                  
                return "发送节目";

            }else{

                return "发送节目";
            }
        }
    },
    {
        name:'devicenumber', index: 'devicenumber',align:"center", width: 30, label: "设备号", align: 'center',


    },
    
    {
        name: 'status', index: 'result',align:"center", width: 30, label: "状态", align: 'center',
        formatter: function (value, options, row) {
                          
            if(parseInt(value) ==1){
              
                return "等待发送";
    
                }
    
             if(parseInt(value)==0){

                return "正在发送";
    
                }
    
             if(parseInt(value)==4){
    
                    return "发送成功";
             }if(parseInt(value)==10){
    
                    return "发送失败";
             }

          return "发送失败";
        }
    },
    {
        name: 'username', index: 'username',align:"center", width: 30, label: "操作人", align: 'center',
        formatter: function (value, options, row) {
                       
            if(typeof(value)!="undefined"){
             
            }
            return "";
         }
    },
    {
        name: 'addTime', index: 'addTime',align:"center", width: 30, label: "时间", align: 'center',
        formatter: function (value, options, row) {
                       
            if(typeof(value)!="undefined"){
                try{
             var date = new Date(value)
                
             return date.Format("yyyy-MM-dd hh:mm:ss");
                }catch(ex){
 
                 console.log(ex);
                }
            }
            return "";
         }
    }
 
],
    pager: "#pager_list_1",
    viewrecords: true,
    // multiselect:true;//选中按钮
    caption: "节目发送列表",
    hidegrid: false,
    ondblClickRow:function(row){
    $("#update").click();
    modify(row);
      // $('#myModal').modal('show')
    },
    onPaging:function(pageBtn){
        console.log(":"+pageBtn);
//	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数
        var re_page =  $("#table_list_1").getGridParam('page');//获取返回的当前页
        var re_rowNum=  $("#table_list_1").getGridParam('rowNum');//获取每页数
        var re_total=  $("#table_list_1").getGridParam('lastpage');//获取总页数
        //alert(re_total);
        
        if(pageBtn==="next"){
           // initJqgrid(re_page+1,re_rowNum);
          // if()
           pageval=pageval+1;
           cxlist();
        }
        if(pageBtn==="prev"){
            
            pageval=pageval-1;  cxlist();
        }

        if(pageBtn=="last"){
  
            pageval=re_total;
          
            cxlist();

        }
        if(pageBtn=="first"){
  
            pageval=1;
          
            cxlist();

        }
        
        if(pageBtn=="records"){

            sizeval=$(".ui-pg-selbox").val();
            pageval=1;
            cxlist();
        }
    },

});
$("#table_list_1").setGridHeight($(window).height() * 0.73);

 $(window).resize(function(){
    $("#table_list_1").setGridWidth($(window).width());  
    $("#table_list_1").setGridHeight($(window).height() * 0.73);
});
});
var sizeval=20;
var pageval=1;
var usernameval=$("#usnameval").val();
var conameval="";
var json="";



window.cxlist=function(){
    
    console.log($("#deviceNumber").val());
   // $("body").mLoading();
    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl+"/Threeinjection/DeviceManagement/queryMessageSendTaskInfo",
        data: {size:sizeval,page:pageval,companyId:sessionStorage.getItem("coid"),sessionid:sessionStorage.getItem("sid"),
                "deviceNumber":$("#deviceNumber").val(),"status":$("#sendState").val(),"startTime":$("#demo_datetime").val(),
                "endTime":$("#demo_endtime").val()},       
         // datatype:"JSON",
        success: function (response) {

          
             
            json=response;
            var data=JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },
               
            };
         
    
       //$("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
       $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
            var re_records = $("#table_list_1").getGridParam('records');
          
            if(re_records==0||re_records==null){
                if($(".norecords").html() == null){
                    $("#table_list_1").parent().append("<div class=\"norecords\">没有符合数据</div>");
                }
                $(".norecords").show();
            }else{

                $(".norecords").hide();
            }

         
           
            // console.log(response);
          
        }
    });
}
 





 Date.prototype.Format = function(fmt)   
{ 
//author:wangweizhen
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}


$(function(){
  cxlist();
    $("#select").click(function(){
        sizeval = 20;
        pageval = 1;
        if($("#demo_datetime").val()!=""&& $("#demo_endtime").val()!=""){
            if($("#demo_datetime").val()>$("#demo_endtime").val()){
                swal("OMG!", "开始时间不能大于结束时间", "error");
                return;
            } 
        }
       cxlist();
    });
   

    $("#sx").click(function(){
        sizeval = 20;
        pageval = 1;
      $("#deviceNumber").val("");
      $("#sendState").val("");
      $("#demo_datetime").val("");
      $("#demo_endtime").val("");
        cxlist();
    });
});




